﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CommonData.SynchronizeDatasetTableAdapters;
using CommonData;

namespace DataCentral.Forms
{
    public partial class AfterSyncMasterForm : CommonData.CommonChildForm
    {
        private string _DestTable = string.Empty;
        public string DestTable
        {
            get {return _DestTable;}
            set {_DestTable = value;}
        }
        public AfterSyncMasterForm(string destTable)
        {
            InitializeComponent();
            //_DestTable = destTable;
            if (!string.IsNullOrEmpty(destTable))
                lbTable.SelectedValue = destTable;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void LoadDataAfterSync()
        {
            switch (_DestTable)
            {
                case "Customer":
                    CustomerTableAdapter daCustomer = new CustomerTableAdapter();
                    daCustomer.Fill(dsSync.Customer);
                    break;
                case "INTran":
                    INTranTableAdapter daINTran = new INTranTableAdapter();
                    daINTran.Fill(dsSync.INTran);
                    break;
                case "Inventory":
                    InventoryTableAdapter daInventory = new InventoryTableAdapter();
                    daInventory.Fill(dsSync.Inventory);
                    break;
                case "SaleRouteDetail":
                    SaleRouteDetailTableAdapter daSaleRouteDetail = new SaleRouteDetailTableAdapter();
                    daSaleRouteDetail.Fill(dsSync.SaleRouteDetail);
                    break;
                case "Salesperson":
                    SalespersonTableAdapter daSalesperson = new SalespersonTableAdapter();
                    daSalesperson.Fill(dsSync.Salesperson);
                    break;
                case "SalesRoute":
                    SalesRouteTableAdapter daSalesRoute = new SalesRouteTableAdapter();
                    daSalesRoute.Fill(dsSync.SalesRoute);
                    break;
                case "SaleTeam":
                    SaleTeamTableAdapter daSaleTeam = new SaleTeamTableAdapter();
                    daSaleTeam.Fill(dsSync.SaleTeam);
                    break;
                case "SlsOrdDsp":
                    SlsOrdDspTableAdapter daSlsOrdDsp = new SlsOrdDspTableAdapter();
                    daSlsOrdDsp.Fill(dsSync.SlsOrdDsp);
                    break;
                case "DspOrdDet":
                    DspOrdDetTableAdapter daDspOrdDet = new DspOrdDetTableAdapter();
                    daDspOrdDet.Fill(dsSync.DspOrdDet);
                    break;
            }
            bsSync.DataSource = dsSync;
            bsSync.DataMember = _DestTable;
            viewAfterSync.PopulateColumns();
        }

        private void AfterSyncMasterForm_Load(object sender, EventArgs e)
        {
            LoadDataAfterSync();
        }

        private void lbTable_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lbTable.SelectedValue != null)
            {
                _DestTable = lbTable.SelectedValue.ToString();
                LoadDataAfterSync();
            }
        }
    }//
}
